function isEmail(email) {
    if (email.search(/^([A-Za-z0-9\u4e00-\u9fa5]+[_|_|.]?)+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/) != -1) {
        return true;
    } else {
        return false;
    }
}

function isPhone(phone) {
    if (phone.search(/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/) != -1) {
        return true;
    } else {
        return false;
    }
}

function submit() {
    var name = $("#int01").val();
    var email = $("#int02").val();
    var content = $("#int03").val();
    if (name) {
        $("#int01").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int01").parent().siblings().removeClass("g1").addClass("gr1")
    }
    if (isEmail(email)) {
        $("#int02").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int02").parent().siblings().removeClass("g1").addClass("gr1")
    }
    if (content) {
        $("#int03").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int03").parent().siblings().removeClass("g1").addClass("gr1")
    }
};

function submit02() {
    var name = $("#int04").val();
    var phone = $("#int05").val();
    var email = $("#int06").val();
    var company = $("#int07").val();
    var content = $("#int08").val();
    if (name) {
        $("#int04").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int04").parent().siblings().removeClass("g1").addClass("gr1")
    }
    if (isPhone(phone)) {
        $("#int05").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int05").parent().siblings().removeClass("g1").addClass("gr1")
    }
    if (isEmail(email)) {
        $("#int06").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int06").parent().siblings().removeClass("g1").addClass("gr1")
    }
    if (company) {
        $("#int07").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int07").parent().siblings().removeClass("g1").addClass("gr1")
    }
    if (content) {
        $("#int08").parent().siblings().removeClass("gr1").addClass("g1")
    } else {
        $("#int08").parent().siblings().removeClass("g1").addClass("gr1")
    }
};
$(document).on("click", ".nav", function () {
    if ($(this).hasClass("nav-active")) {
        $(this).removeClass("nav-active");
    } else {
        $(this).addClass("nav-active").siblings().removeClass("nav-active");
    }
});
$(".nav-fr-m").on("click", ".nav", function () {
    if ($(this).hasClass("nav-active")) {
    } else {
        $(this).addClass("nav-active");
        $(this).parent().siblings().children().removeClass("nav-active")
    }

});

$(document).on("click", ".pro-img-item", function () {
    let data_id = $(this).data('id');
    $.ajax({
        url: 'http://jiaju.local.com/pro/' + data_id,
        type: 'get',
        async: true,
        timeOut: 50000,
        dataType: 'json',
        data: [],
        beforeSend: function () {
            //函数体，数据发送前执行。
            $('#image').html('');
            $('#micro-img').html('');
            $('#title').html('');
            $('#type').html('');
            $('#material').html('');
            $('#size').html('');
            $('#color').html('');
            $('#bag-type').html('');
            $('#de-de').html('<div class="spinner"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div>');
            $(".zz6").removeClass("hide");
            $(".tc-pro").addClass("tc-pro-add");
        },
        success: function (data, textStatus, jqHXR) {
            //函数体，数据发送成功回调
            console.log(data);
            let alone_data = data[0][0];
            let image_data = data[1];
            $('#title').html(alone_data['title']);
            $('#type').html(alone_data['type']);
            $('#material').html(alone_data['material']);
            $('#size').html(alone_data['size']);
            $('#color').html(alone_data['color']);
            $('#bag-type').html(alone_data['bag_type']);
            $('#de-de').html(alone_data['de_de']);
            let image_html = '';
            let micro_img_html = '';
            for (let i = 0; i < image_data.length; i++) {
                image_html = image_html + '<div class="swiper-slide swiper-slide5" style="background-image:url(' + 'http://jiaju.local.com/storage/uploads/' + image_data[i]['image'] + ')"></div>';
                micro_img_html = micro_img_html + '<div class="swiper-slide swiper-slide5" style="background-image:url(' + 'http://jiaju.local.com/storage/uploads/' + image_data[i]['micro_img'] + ')"></div>';
            }
            $('#image').html(image_html);
            $('#micro-img').html(micro_img_html);
        },
        error: function (xhr, textStatus) {
            //函数体，数据发送失败回调
            console.log(xhr + textStatus);
        },
    });
    return false;
});
$(".zz6-err").click(function () {
    $(".zz6").addClass("hide");
    $(".tc-pro").removeClass("tc-pro-add")
});
$(".container-close").click(function () {
    $(".zz6").addClass("hide");
    $(".tc-pro").removeClass("tc-pro-add")
});

var galleryTop = new Swiper('.gallery-top5', {
    spaceBetween: 10,
    loop: true,
    loopedSlides: 5, //looped slides should be the same
    navigation: {
        nextEl: '.swiper-button-next5',
        prevEl: '.swiper-button-prev5',
    },

    observer: true,//修改swiper自己或子元素时，自动初始化swiper

    observeParents: true//修改swiper的父元素时，自动初始化swiper
});
var galleryThumbs = new Swiper('.gallery-thumbs5', {
    spaceBetween: 8,
    slidesPerView: 4.5,
    touchRatio: 0.2,
    loop: true,
    loopedSlides: 5, //looped slides should be the same
    slideToClickedSlide: true,

    observer: true,//修改swiper自己或子元素时，自动初始化swiper

    observeParents: true//修改swiper的父元素时，自动初始化swiper
});
galleryTop.controller.control = galleryThumbs;
galleryThumbs.controller.control = galleryTop;


var swiper = new Swiper('.swiper-container6', {
    slidesPerView: 4.6,
    spaceBetween: 30,
    pagination: {
        el: '.swiper-pagination6',
        clickable: true,
    },
});


$(document).on("click", ".nav", function () {
    let item_id = $(this).data('id');
    console.log(item_id);
    $.ajax({
        url: 'http://jiaju.local.com/pro/item/' + item_id,
        type: 'get',
        async: true,
        timeOut: 50000,
        dataType: 'json',
        data: [],
        beforeSend: function () {
            //函数体，数据发送前执行。
            if ($(this).hasClass("nav-set")) {
                $(".share-item").removeClass("hide");
            } else {
                $(".share-item").addClass("hide");
            }
            $('.pro-container-top-contaienr').html(
                '<div class="spinner"><div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div><div class="rect5"></div></div>'
            );
        },
        success: function (data, textStatus, jqHXR) {
            //函数体，数据发送成功回调
            console.log(data);
            let alone = '';
            for (let i = 0; i < data.length; i++) {
                alone = alone + '<div class="pro-img-item fl" data-id="' + data[i]['id'] + '"><a href="#"><img class="pro-img-item-img" src="http://jiaju.local.com/storage/uploads/' + data[i]['show_img'] + '"/><div class="zz-02"><div class="zz-02-t">' + data[i]['title'] + '</div></div><div class="move-add-bottom-nav hide">' + data[i]['zh_type'] + '</div></a></div>';
            }
            $('.pro-container-top-contaienr').html(alone);
        },
        error: function (xhr, textStatus) {
            //函数体，数据发送失败回调
            console.log(xhr + textStatus);
        },
    });
});

$(document).on("click", ".share-along", function () {
    window.location.href = 'share-alone.html'
});

$(document).on("click", ".share-item", function () {
    window.location.href = 'share-item.html'
})


